using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PureMVC.Patterns.Mediator;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class HpMediator : Mediator
{
    private TMP_Text _hpText;
    private Slider _hpSlider;

    public HpMediator(string mediatorName, object viewComponent = null) : base(mediatorName, viewComponent)
    {
        _hpText = ((GameObject)viewComponent).transform.Find("hpText").GetComponent<TMP_Text>();
        _hpSlider = ((GameObject)viewComponent).transform.Find("hpSlider").GetComponent<Slider>();
    }
    
    public override string[] ListNotificationInterests()
    {
        IList<string> interests = new List<string>();
        interests.Add(Notifications.HpChanged);
        return interests.ToArray();
    }
    
    public override void HandleNotification(PureMVC.Interfaces.INotification notification)
    {
        switch (notification.Name)
        {
            case Notifications.HpChanged:
                float hp = (float)notification.Body;
                _hpText.text = "HP: " + hp.ToString("F0");
                _hpSlider.value = hp / 100f;
                break;
        }
    }
}
